<?php
/**
 * Created by PhpStorm.
 * User: liuyiwei@7659.com
 * Date: 2018/9/27
 * Time: 13:49
 */

namespace backend\helpers;


class ClientHelper
{
    /**
     * 当前赛事报名方式 1:预约码报名 2:公开报名
     * @param $data
     * @return int
     */
    public static function currentJoinMethod($data) {
        if ($data['status'] != 0 || $data['status2'] != 1) {
            return 0;
        }

        if ($data['status2_flag'] == 10) {
            return 1;
        }

        return 2;
    }

    /**
     * 赛事报名方式 1:内部预留 2:邀请报名 3:公开报名
     * @todo
     * @param $data
     * @return int
     */
    public static function matchJoinMethod($data) {

    }

    /**
     * 比赛状态 0:未开始报名 1:正在报名 2:报名满员 3:报名截止 4:比赛开始 5:比赛结束
     * @param $data
     * @return int
     */
    public static function matchStatus($data) {
        if ($data['status'] == 0) {
            if ($data['status2'] == 1) {
                return 1;
            } elseif ($data['status2'] == 3) {
                return 2;
            } elseif ($data['status2'] == 2) {
                return 3;
            }
        } elseif ($data['status'] == 1) {
            return 4;
        } elseif ($data['status'] == 2) {
            return 5;
        } else {
            return 5;
        }
    }

    /**
     * 报名开始时间
     * @param $data
     * @return mixed
     */
    public static function matchEnrollTime($data) {
        if (!is_null($data['enroll_time_invite']) && !empty($data['enroll_time_invite']) && $data['player_num_invite'] > 0) {
            return $data['enroll_time_invite'];
        }
        return $data['enroll_time'];
    }

    /**
     * 获取扩展字段值
     * @param $data
     * @param $key
     * @return string
     */
    public static function getMatchExtra($data, $key) {
        $extra = @json_decode($data['extra'], 1);
        return isset($extra[$key]) ? $extra[$key] : '';
    }

    /**
     * 最大报名战队数或者人数
     * @param $data
     * @return float|int
     */
    public static function getMatchMaxTeams($data) {
        if ($data['flag'] == 2) {
            return $data['player_num_max'];
        }
        if ($data['player_num_float'] <= 0) {
            return $data['player_num_max']/$data['game_specs'];
        }
        return $data['team_num_max'];
    }

    /**
     * 卡片类型 1:无图 2:中图 3:大图 4：视频专题
     * @param $data
     */
    public static function getCardType($data) {
        if (!empty($data['photo_url'])) {
            return 3;
        } elseif (!empty($data['thumbnail_url'])) {
            return 2;
        } else {
            return 1;
        }
    }
}